/**
  * Author: Mei
  * Date: 2020-12-09 15:25
  * Description: 关键字explicit(显性的)
  *
  */
#include <vector>
#include <iostream>
#include <bitset>
#include <algorithm>

using namespace std;

struct Complex {
    double real, imag;

    Complex(double r, double i = 10) : real(r), imag(i) {}

    //explicit告诉编译器自己明确调用  不要帮我自动转换  那么5转Complex就会失败
    explicit Complex(double r, double i = 10) : real(r), imag(i) {}

    Complex operator+(const Complex &c) {
        return Complex(real + c.real, imag + c.imag);
    }

    void display() {
        cout << "real=" << real << ",imag=" << imag << endl;
    }
};

int main() {
    //以前的用法
    Complex c(12, 5);
    Complex c1 = c + 5; //将5隐式转化为Complex对象  加了explicit会失败
    c1.display();

    return 0;
}